package com.geo.fight;

import java.awt.event.KeyEvent;
import java.util.ArrayList;

public class Gunner {
	/**
	 * @author Geo
	 */
	private ArrayList<Missile> missiles = new ArrayList<>();
	private double mxPos;
	private double myPos;
	private final int gunLength = 100;
	private final int gunWidth = 20;
	private double dTheta = 0.0;
	private double theta;
	
	public Gunner(){
		
		theta = 0;
	}
	
	
	public void fire(){
		Missile m = new Missile(mxPos,myPos);
		m.setTheta(theta);
		missiles.add(m);
		//System.out.println("Fire mXpos "+mxPos+" myPos "+myPos);
	}

	
	public void rotate(){
		theta+=dTheta;
	}
	
	public void stopRotateLeft(){
		theta = 0;
		//System.out.println("Stop left "+theta);
	}
	public void stopRotateRight(){
		theta = 0;
		//System.out.println("Stop right "+theta);
	}
	
	public ArrayList<Missile> getMissiles(){
		return missiles;
	}
	
	
	
	public void keyPressed(KeyEvent e){
		int keyCode = e.getKeyCode();
		if(keyCode==KeyEvent.VK_LEFT){
			dTheta = -1;
		}
		if(keyCode==KeyEvent.VK_RIGHT){
			dTheta = 1;
		}
		if(keyCode==KeyEvent.VK_SPACE){
			fire();
		}
	}
	public void keyReleased(KeyEvent e){
		int keyCode = e.getKeyCode();
		if(keyCode==KeyEvent.VK_LEFT){
			dTheta = 0;
		}
		if(keyCode==KeyEvent.VK_RIGHT){
			dTheta = 0;
		}
		
	}
	
	
	public int getGunHight(){
		return gunLength;
	}
	public int getGunWidth(){
		return gunWidth;
	}
	public double getTheta(){
		return theta;
	}
	public void setMxpos(double mxPos){
		this.mxPos = mxPos;
	}
	public void setMypos(double myPos){
		this.myPos = myPos;
	}
}
